<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="google-site-verification" content="yaeorbXgKPwp5BDegBtAJEHYWFEFE-BViWTj74gJPrw" />
<!--  -->
<link href="/css/default.css" type="text/css" rel="stylesheet" />
<!--  -->
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/lang/cn.js"></script>
<script type="text/javascript" src="/js/mac/core.min.js"></script>
<title>JQuery MagicCombo Grid单选示例</title>
<link type="text/css" rel="stylesheet" href="/css/default/mac/combo/combo.min.css" />
<script type="text/javascript" src="/js/mac/combo.min.js"></script>
</head>
<body>
<link href="/css/default/mac/grid/grid.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/js/jquery/mousewheel.js"></script>
<script type="text/javascript" src="/js/mac/pager.min.js"></script>
<script type="text/javascript" src="/js/mac/grid.min.js"></script>
<script type="text/javascript">
$(function(){
	var gd1 = $('<div class="grid"></div>').mac('grid', {
		key: 'no',
		cols : [{
			field: 'subject', title : 'Subject', width: 150
		},{
			field: 'summary', title : 'Summary', width: 150
		},{
			field: 'debit', title : 'Debbit', width: 80, sort: true,
			render: function(r, tr){
				return '<div class="money">$'+r.debit+'</div>';
			}
		},{
			field: 'credit', title : 'Credit', width: 80, sort: true,
			render: function(r, tr){
				return '<div class="money">$'+r.credit+'</div>';
			}
		}],
		loader: {
			url: '/mac/js/grid/data.php',
			params: { pageNo: 1, pageSize: 20 },
			autoLoad: true
		},
		pagerLength: 10,
		onRowClick: function(){
			var ec = $(this);
			gd1.find('.tr').removeClass('selected');
			ec.addClass('selected');
			var k = ec.attr('name');
			gd1.selected = {};
			gd1.selected[k] = gd1.data[k];
			cb1.select(gd1.data[k]);
			cb1.close();
		},
		afterLoad: function(dd, po){
			gd1.select(cb1.selected);
		}
	});
	gd1.select = function(sl){
		var at = gd1.find('.tr').removeClass('selected');
		$.each(sl, function(n, r){
			at.filter("[name='" + r.no + "']").addClass('selected');
		});
	}
	var cb1 = $('#combo1').mac('combo', {
		keyField: 'no',
		displayField: 'subject',
		boxWidth: 490,
		boxHeight: 300,
		width: 200,
		boxEl: gd1,
		multiSelect: false,
		onOpen: function(){
			gd1.adjust();
			gd1.select(cb1.selected);
		}
	});
	$('#get1').click(function(){
		alert(JSON.stringify(cb1.selected[0]));
	});
	$('#set1').click(function(){
		cb1.select({ no: 2, subject: 'Subject 002' });
	});
});
</script>
<div id="combo1" class="combo customCombo"></div><br/>
&nbsp;&nbsp;<button id="get1">get1</button>&nbsp;<button id="set1">set1</button></body>
</html>
